<template>
	<div>
		<el-menu :default-active="this.$router.path"            
      router			 class="d-flex" mode="horizontal" type="flex" index="1">
			<el-menu-item class="mr-auto" index="/space"><div>
				<img id="header" src='' class="circleImg" />
				</div></el-menu-item>
			<el-menu-item index="/">{{$t("header.home")}}</el-menu-item>
			<el-menu-item index="/login">登录</el-menu-item>
			<el-menu-item index="/search">搜索</el-menu-item>
				<el-menu-item index="/add">上传文章</el-menu-item>
			<!--<el-submenu index="2">
				<template slot="title">{{$t("header.language")}}</template>
				<el-menu-item @click="toggleLang('zh')" >{{$t("header.chinaese")}}</el-menu-item>
				<el-menu-item @click="toggleLang('en')">{{$t("header.english")}}</el-menu-item>
			</el-submenu>-->
		</el-menu>
	</div>
</template>

<script>
import $ from 'jquery'
import axios from 'axios'
//import func from '../../vue-temp/vue-editor-bridge'
//import img from '../static/img'



	export default {
		data() {
			return {
				activeIndex: '/',
				head_url: ''
		}
		},
		methods: {
				loadHead: function () {
				var unknown_url = '../assets/unknown.jpg'
				if (localStorage.getItem('auth') == null ){
					return unknown_url
					this.head_url = unknown_url
				}else{
					return '../assets/mayun.png'
					this.head_url = '../assets/mayun.png'
				}

		},
			toggleLang(lang) {
				if(lang === 'zh') {
					localStorage.setItem('locale', 'zh')
					this.$i18n.locale = localStorage.getItem('locale')
					this.$message({
						message: '切换为中文！',
						type: 'success'
					})
				} else if(lang === 'en') {
					localStorage.setItem('locale', 'en')
					this.$i18n.locale = localStorage.getItem('locale')
					this.$message({
						message: 'Switch to English!',
						type: 'success'
					})
				}
			}
		},
		created(){
	
		$(function(){
	var unknown_url = 'unknown.jpg'

if (localStorage.getItem('auth') == null ){
					$('#header').attr('src',require('../assets/'+unknown_url))
					
				}else{
 
        axios.post('/user/space',{},
     {
       headers: {
						'Authorization': localStorage.getItem('auth')
				}

      }
       

        ).then
        (
          resp => {
            var auth=resp.headers.authorization
					 // this.$store.commit("auth",auth )\
					 $('#header').attr('src','http://127.0.0.1:7071/static/'+resp.data.data.photo)
           console.log(resp)

          }
          ).catch(err => {
						localStorage.removeItem('auth')
						$('#header').attr('src',require('../assets/'+unknown_url))
            console.log(err);
          })
        




					console.log('5511551'+localStorage.getItem('auth'))
					//$('#header').attr('src',require('../assets/mayun.png'))
			
				}
	console.log($('#header')[0].src)
})
		}
	
	}

</script>

<style scoped>

</style>